
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.1 导入数据 · 大数据 Azkaban 课堂笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content=" 李振超">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-change_girls/girls.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/website.css">
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="32-dao-chu-shu-ju.html" />
    
    
    <link rel="prev" href="../di-3-zhang-sqoop-jian-dan-shi-yong-an-li.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://www.atguigu.com/" target="_blank" class="custom-link">联系我们</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    第 1 章 Sqoop 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    第 2 章 Sqoop 安装和配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../di-3-zhang-sqoop-jian-dan-shi-yong-an-li.html">
            
                <a href="../di-3-zhang-sqoop-jian-dan-shi-yong-an-li.html">
            
                    
                    第 3 章 Sqoop 简单使用案例
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="31-dao-ru-shu-ju.html">
            
                <a href="31-dao-ru-shu-ju.html">
            
                    
                    3.1 导入数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="32-dao-chu-shu-ju.html">
            
                <a href="32-dao-chu-shu-ju.html">
            
                    
                    3.2 导出数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="33-jiao-ben-da-bao.html">
            
                <a href="33-jiao-ben-da-bao.html">
            
                    
                    3.3 脚本打包
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu.html">
            
                    
                    第 4 章 Sqoop 的一些常用命令和参数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/41-chang-yong-ming-ling-lie-ju.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/41-chang-yong-ming-ling-lie-ju.html">
            
                    
                    4.1 常用命令列举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie.html">
            
                    
                    4.2 命令和参数详解
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/421-gong-yong-can-shu-ff1a-shu-ju-ku-lian-jie.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/421-gong-yong-can-shu-ff1a-shu-ju-ku-lian-jie.html">
            
                    
                    4.2.1 公用参数：数据库连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/422-gong-yong-can-shu-ff1a-import.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/422-gong-yong-can-shu-ff1a-import.html">
            
                    
                    4.2.2 公用参数：import
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/423-gong-yong-can-shu-ff1a-export.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/423-gong-yong-can-shu-ff1a-export.html">
            
                    
                    4.2.3 公用参数：export
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.4" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/424-gong-yong-can-shu-ff1a-hive.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/424-gong-yong-can-shu-ff1a-hive.html">
            
                    
                    4.2.4 公用参数：hive
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.5" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/425-ming-4ee426-can-shu-ff1a-import.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/425-ming-4ee426-can-shu-ff1a-import.html">
            
                    
                    4.2.5 命令&参数：import
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.6" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/426-ming-4ee426-can-shu-ff1a-export.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/426-ming-4ee426-can-shu-ff1a-export.html">
            
                    
                    4.2.6 命令&参数：export
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.7" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/427-ming-4ee426-can-shu-ff1a-codegen.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/427-ming-4ee426-can-shu-ff1a-codegen.html">
            
                    
                    4.2.7 命令&参数：codegen
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.8" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/428-ming-4ee426-can-shu-ff1a-create-hive-table.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/428-ming-4ee426-can-shu-ff1a-create-hive-table.html">
            
                    
                    4.2.8 命令&参数：create-hive-table
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.9" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/429-ming-4ee426-can-shu-ff1a-eval.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/429-ming-4ee426-can-shu-ff1a-eval.html">
            
                    
                    4.2.9 命令&参数：eval
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.10" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4210.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4210.html">
            
                    
                    4.2.10 命令&参数：import-all-tables
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.11" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4211-ming-4ee426-can-shu-ff1a-job.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4211-ming-4ee426-can-shu-ff1a-job.html">
            
                    
                    4.2.11 命令&参数：job
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.12" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4212.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4212.html">
            
                    
                    4.2.12 命令&参数：list-databases
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.13" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4213-jiang-hdfs-zhong-bu-tong-mu-lu-xia-mian-de-shu-ju-he-bing-zai-yi-qi-bing-fang-ru-zhi-ding-mu-lu-zhong.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4213-jiang-hdfs-zhong-bu-tong-mu-lu-xia-mian-de-shu-ju-he-bing-zai-yi-qi-bing-fang-ru-zhi-ding-mu-lu-zhong.html">
            
                    
                    4.2.13 命令&参数：merge
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.14" data-path="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4214-ming-4ee426-can-shu-ff1a-metastore.html">
            
                <a href="../di-4-zhang-sqoop-de-yi-xie-chang-yong-he-can-shu/42-ming-ling-he-can-shu-xiang-jie/4214-ming-4ee426-can-shu-ff1a-metastore.html">
            
                    
                    4.2.14 命令&参数：metastore
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3.1 导入数据</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="31-&#x5BFC;&#x5165;&#x6570;&#x636E;">3.1 &#x5BFC;&#x5165;&#x6570;&#x636E;</h1>
<p>&#x5728; Sqoop &#x4E2D;, &#x6570;&#x636E;&#x7684;&#x5BFC;&#x5165;&#x6216;&#x8005;&#x5BFC;&#x51FA;&#x90FD;&#x662F;&#x7AD9;&#x5728;&#x5927;&#x6570;&#x636E;&#x96C6;&#x7FA4;&#x7684;&#x89D2;&#x5EA6;&#x6765;&#x770B;&#x7684;:</p>
<p>&#x5982;&#x679C;&#x628A;&#x6570;&#x636E;&#x4ECE;<my>&#x975E;&#x5927;&#x6570;&#x636E;&#x96C6;&#x7FA4;(mysql)&#x5230;&#x5927;&#x6570;&#x636E;&#x96C6;&#x7FA4;(HDFS&#xFF0C;HIVE&#xFF0C;HBASE) &#x53EB;&#x505A;&#x5BFC;&#x5165;</my>&#x53CD;&#x4E4B;&#x5C31;&#x662F;&#x5BFC;&#x51FA;</p>
<hr>
<h2 id="311-&#x4ECE;&#x666E;&#x901A;&#x6570;&#x636E;&#x5E93;mysql-&#x5230;-hdfs">3.1.1 &#x4ECE;&#x666E;&#x901A;&#x6570;&#x636E;&#x5E93;(mysql) &#x5230; HDFS</h2>
<h3 id="&#x6B65;&#x9AA4;1-&#x786E;&#x8BA4;-mysql-&#x670D;&#x52A1;&#x6B63;&#x5E38;&#x542F;&#x52A8;">&#x6B65;&#x9AA4;1: &#x786E;&#x8BA4; Mysql &#x670D;&#x52A1;&#x6B63;&#x5E38;&#x542F;&#x52A8;</h3>
<pre class="language-"><code class="lang-bash"><span class="token function">sudo</span> <span class="token function">service</span> mysql status
</code></pre>
<p><img src="http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/1542509182.png-atguiguText" alt=""></p>
<h3 id="&#x6B65;&#x9AA4;2-&#x5728;-mysql-&#x4E2D;&#x65B0;&#x5EFA;&#x4E00;&#x5F20;&#x8868;&#x5E76;&#x63D2;&#x5165;&#x4E00;&#x4E9B;&#x6570;&#x636E;">&#x6B65;&#x9AA4;2: &#x5728; Mysql &#x4E2D;&#x65B0;&#x5EFA;&#x4E00;&#x5F20;&#x8868;&#x5E76;&#x63D2;&#x5165;&#x4E00;&#x4E9B;&#x6570;&#x636E;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">create</span> <span class="token keyword">database</span> company<span class="token punctuation">;</span>
<span class="token keyword">create</span> <span class="token keyword">table</span> company<span class="token punctuation">.</span>staff<span class="token punctuation">(</span>id <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span> <span class="token keyword">primary</span> <span class="token keyword">key</span> <span class="token operator">not</span> <span class="token boolean">null</span> <span class="token keyword">auto_increment</span><span class="token punctuation">,</span> name <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">,</span> sex <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">insert</span> <span class="token keyword">into</span> company<span class="token punctuation">.</span>staff<span class="token punctuation">(</span>name<span class="token punctuation">,</span> sex<span class="token punctuation">)</span> <span class="token keyword">values</span><span class="token punctuation">(</span><span class="token string">&apos;zangsan&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;Male&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> company<span class="token punctuation">.</span>staff<span class="token punctuation">(</span>name<span class="token punctuation">,</span> sex<span class="token punctuation">)</span> <span class="token keyword">values</span><span class="token punctuation">(</span><span class="token string">&apos;lisi&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;Male&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> company<span class="token punctuation">.</span>staff<span class="token punctuation">(</span>name<span class="token punctuation">,</span> sex<span class="token punctuation">)</span> <span class="token keyword">values</span><span class="token punctuation">(</span><span class="token string">&apos;wangwu&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;Male&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> company<span class="token punctuation">.</span>staff<span class="token punctuation">(</span>name<span class="token punctuation">,</span> sex<span class="token punctuation">)</span> <span class="token keyword">values</span><span class="token punctuation">(</span><span class="token string">&apos;zhiling&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;Male&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> company<span class="token punctuation">.</span>staff<span class="token punctuation">(</span>name<span class="token punctuation">,</span> sex<span class="token punctuation">)</span> <span class="token keyword">values</span><span class="token punctuation">(</span><span class="token string">&apos;fengjie&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;Male&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p><img src="http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/1542509458.png-atguiguText" alt=""></p>
<h3 id="&#x6B65;&#x9AA4;3-&#x5F00;&#x59CB;&#x5BFC;&#x5165;&#x6570;&#x636E;">&#x6B65;&#x9AA4;3: &#x5F00;&#x59CB;&#x5BFC;&#x5165;&#x6570;&#x636E;</h3>
<h4 id="1-&#x5168;&#x90E8;&#x5BFC;&#x5165;">1. &#x5168;&#x90E8;&#x5BFC;&#x5165;</h4>
<pre class="language-"><code class="lang-bash">sqoop <span class="token function">import</span> \
--connect jdbc:mysql://hadoop201:3306/company \
--username root \
--password aaa \
--table staff \
--target-dir /user/company \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by <span class="token string">&quot;\t&quot;</span>
</code></pre>
<p><img src="http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/1542509686.png-atguiguText" alt=""></p>
<h4 id="2-&#x67E5;&#x8BE2;&#x5BFC;&#x5165;free-form-query-imports">2. &#x67E5;&#x8BE2;&#x5BFC;&#x5165;(Free-form Query Imports)</h4>
<pre class="language-"><code class="lang-bash">sqoop <span class="token function">import</span> \
--connect jdbc:mysql://hadoop201:3306/company \
--username root \
--password aaa \
--target-dir /user/company \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by <span class="token string">&quot;\t&quot;</span> \
--query <span class="token string">&apos;select name,sex from staff where id &lt;=2 and <span class="token variable">$CONDITIONS</span>&apos;</span>
</code></pre>
<blockquote>
<h4 id="&#x6CE8;&#x610F;"><em>&#x6CE8;&#x610F;:</em></h4>
</blockquote>
<ul>
<li>&#x4F7F;&#x7528; <code>--query</code> &#x7684;&#x65F6;&#x5019;, &#x5FC5;&#x987B;&#x5728; <code>where</code> &#x5B50;&#x53E5;&#x4E2D;&#x6DFB;&#x52A0; <code>$CONDITIONS</code>.</li>
<li>&#x5982;&#x679C; <code>--query</code> &#x540E;&#x9762;&#x8DDF;&#x7684;&#x662F;&#x53CC;&#x5F15;&#x53F7;, &#x5219;&#x9700;&#x8981;&#x4F7F;&#x7528; <code>\$CONDITIONS</code>.</li>
</ul>
<h4 id="3-&#x5BFC;&#x5165;&#x6307;&#x5B9A;&#x5217;">3. &#x5BFC;&#x5165;&#x6307;&#x5B9A;&#x5217;</h4>
<pre class="language-"><code class="lang-bash">sqoop <span class="token function">import</span> \
--connect jdbc:mysql://hadoop201:3306/company \
--username root \
--password aaa \
--table staff \
--columns id,sex \
--target-dir /user/company \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by <span class="token string">&quot;\t&quot;</span>
</code></pre>
<blockquote>
<h4 id="&#x6CE8;&#x610F;"><em>&#x6CE8;&#x610F;:</em></h4>
</blockquote>
<ul>
<li><code>--columns</code> &#x4E2D;&#x5982;&#x679C;&#x6D89;&#x53CA;&#x5230;&#x591A;&#x5217;&#x7528;&#x9017;&#x53F7;&#x5206;&#x9694;&#xFF0C;&#x5206;&#x9694;&#x65F6;&#x4E0D;&#x8981;&#x6DFB;&#x52A0;&#x7A7A;&#x683C;. &#x5426;&#x5219;&#x4F1A;&#x629B;&#x5F02;&#x5E38;</li>
</ul>
<h4 id="4-&#x4F7F;&#x7528;-sqoop-&#x5173;&#x952E;&#x5B57;&#x7B5B;&#x9009;&#x67E5;&#x8BE2;&#x5BFC;&#x5165;&#x6570;&#x636E;">4. &#x4F7F;&#x7528; sqoop &#x5173;&#x952E;&#x5B57;&#x7B5B;&#x9009;&#x67E5;&#x8BE2;&#x5BFC;&#x5165;&#x6570;&#x636E;</h4>
<pre class="language-"><code class="lang-bash">sqoop <span class="token function">import</span> \
--connect jdbc:mysql://hadoop201:3306/company \
--username root \
--password aaa \
--where <span class="token string">&apos;id=1&apos;</span> \
               \
--target-dir /user/company \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by <span class="token string">&quot;\t&quot;</span> \
--table staff
</code></pre>
<hr>
<h2 id="312-&#x4ECE;&#x666E;&#x901A;&#x6570;&#x636E;&#x5E93;mysql-&#x5230;-hive">3.1.2 &#x4ECE;&#x666E;&#x901A;&#x6570;&#x636E;&#x5E93;(mysql) &#x5230; Hive</h2>
<pre class="language-"><code>sqoop import \
--connect jdbc:mysql://hadoop201:3306/company \
--username root \
--password aaa \
--table staff \
              \
--num-mappers 1 \
--hive-import \
--fields-terminated-by &quot;\t&quot; \
--hive-overwrite \
--delete-target-dir \
--hive-table staff_hive
</code></pre><blockquote>
<h4 id="&#x6CE8;&#x610F;"><em>&#x6CE8;&#x610F;:</em></h4>
</blockquote>
<ul>
<li><p>&#x5982;&#x679C;&#x629B;&#x51FA;&#x5F02;&#x5E38;:<code>Could not load org.apache.hadoop.hive.conf.HiveConf. Make sure HIVE_CONF_DIR is set correctly</code>, &#x5219;&#x9700;&#x8981;&#x628A;<code>$HIVE_HOME/lib/*</code>&#x52A0;&#x5165;&#x5230;&#x73AF;&#x5883;&#x53D8;&#x91CF;<code>HADOOP_CLASSPATH</code> &#x4E2D;</p>
<p>&#x5728;<code>sqopp-env.sh</code> &#x4E0B;&#x6DFB;&#x52A0;&#x5982;&#x4E0B;&#x4EE3;&#x7801;:</p>
<pre class="language-"><code class="lang-`">export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$HIVE_HOME/lib/*
</code></pre>
</li>
<li><p>&#x8BE5;&#x8FC7;&#x7A0B;&#x5206;&#x4E3A;&#x4E24;&#x6B65;&#xFF0C;&#x7B2C;&#x4E00;&#x6B65;&#x5C06;&#x6570;&#x636E;&#x5BFC;&#x5165;&#x5230; HDFS&#xFF0C;&#x7B2C;&#x4E8C;&#x6B65;&#x5C06;&#x5BFC;&#x5165;&#x5230; HDFS &#x7684;&#x6570;&#x636E;&#x8FC1;&#x79FB;&#x5230;Hive &#x4ED3;&#x5E93;&#xFF0C;&#x7B2C;&#x4E00;&#x6B65;&#x9ED8;&#x8BA4;&#x7684;&#x4E34;&#x65F6;&#x76EE;&#x5F55;&#x662F;<code>/user/atguigu/&#x8868;&#x540D;</code></p>
</li>
</ul>
<hr>
<h2 id="313-&#x4ECE;&#x666E;&#x901A;&#x6570;&#x636E;&#x5E93;mysql-&#x5230;-hbase">3.1.3 &#x4ECE;&#x666E;&#x901A;&#x6570;&#x636E;&#x5E93;(mysql) &#x5230; HBase</h2>
<pre class="language-"><code class="lang-bash">sqoop <span class="token function">import</span> \
--connect jdbc:mysql://hadoop201:3306/company \
--username root \
--password aaa \
--table staff \
              \
--hbase-table <span class="token string">&quot;hbase_company&quot;</span> \
--column-family <span class="token string">&quot;info&quot;</span> \
--columns <span class="token string">&quot;id,name,sex&quot;</span> \
--hbase-create-table \
--hbase-row-key <span class="token string">&quot;id&quot;</span> \
--num-mappers 1 \
--split-by <span class="token function">id</span>
</code></pre>
<p><img src="http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/1542513830.png-atguiguText" alt=""></p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x5C1A;&#x7845;&#x8C37;&#x5927;&#x6570;&#x636E; 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification"><br>&#x8BE5;&#x6587;&#x4EF6;&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2019-03-30 20:28:58
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../di-3-zhang-sqoop-jian-dan-shi-yong-an-li.html" class="navigation navigation-prev " aria-label="Previous page: 第 3 章 Sqoop 简单使用案例">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="32-dao-chu-shu-ju.html" class="navigation navigation-next " aria-label="Next page: 3.2 导出数据">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.1 导入数据","level":"1.3.1","depth":2,"next":{"title":"3.2 导出数据","level":"1.3.2","depth":2,"path":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/32-dao-chu-shu-ju.md","ref":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/32-dao-chu-shu-ju.md","articles":[]},"previous":{"title":"第 3 章 Sqoop 简单使用案例","level":"1.3","depth":1,"path":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li.md","ref":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li.md","articles":[{"title":"3.1 导入数据","level":"1.3.1","depth":2,"path":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/31-dao-ru-shu-ju.md","ref":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/31-dao-ru-shu-ju.md","articles":[]},{"title":"3.2 导出数据","level":"1.3.2","depth":2,"path":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/32-dao-chu-shu-ju.md","ref":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/32-dao-chu-shu-ju.md","articles":[]},{"title":"3.3 脚本打包","level":"1.3.3","depth":2,"path":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/33-jiao-ben-da-bao.md","ref":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/33-jiao-ben-da-bao.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["splitter","expandable-chapters-small","page-toc-button","-highlight","prism","prism-themes","tbfed-pagefooter","sitemap","change_girls","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 尚硅谷大数据 2019","modify_label":"<br>该文件最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"]},"disqus":{"shortName":"zhenchao125"},"livereload":{},"splitter":{},"change_girls":{"time":30,"urls":["http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/62171757.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/83394736.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/15906185.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3394270.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/65028582.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/20359261.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/37472401.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/3355397.jpg-atguiguImg","http://lizhenchao.oss-cn-shenzhen.aliyuncs.com/imgs/18-3-4/11075549.jpg-atguiguImg"]},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"sitemap":{"hostname":"http://bigdataatguigu.applinzi.com/"},"page-toc-button":{"maxTocDepth":3,"minTocSize":2},"prism-themes":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":" 李振超","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"大数据 Azkaban 课堂笔记","language":"zh-hans","links":{"sidebar":{"联系我们":"http://www.atguigu.com/"}},"gitbook":"*","description":"课堂笔记,学生提前预习"},"file":{"path":"di-3-zhang-sqoop-jian-dan-shi-yong-an-li/31-dao-ru-shu-ju.md","mtime":"2019-03-30T12:28:58.850Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-03-30T12:30:16.985Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-change_girls/girls.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

